import {
  SpreadModel
} from '../../models/spread'
import {
  Format
}
from "../../utils/common";
import {
  OrderModel
} from "../../models/order";
const spreadModel = new SpreadModel()
const format = new Format()
const app = getApp()
const orderModel = new OrderModel()
let timerCountDown = {}
let timerDate = {}
Page({
  data: {
    canUse: wx.canIUse('lifestyle'),
    countDownTime: {
      m: 0,
      s: 0,
      ms: 0
    },
    detail: {
      amount: 0,
      realAmount: 0,
      merchantSubsidyAmount: 0
    }
  },
  onLoad(query) {
    console.log(query)
    app.globalData.entityNum = ''
    // query.tradeNo = '2019111322001491075728330373'
    const time = format.date("yyyy年MM月dd日 hh:mm:ss", new Date())
    this.setData({
      time: time
    })
    this.loadDetail(query.tradeNo)
    this.showTime()
  },
  loadDetail(tradeNo) {
    orderModel.loadDetail(tradeNo).then(res => {
      console.log('111111' + JSON.stringify(res))
      this.setData({
        detail: res,
      })
    })
  },
  toPage(e) {
    const page = e.currentTarget.dataset.url
    // wx.switchTab({
    //   url: page
    // })
    wx.redirectTo({
      url: page 
    })
  },
  toMayi() {
    // wx.navigateToMiniProgram({
    //   appId: '2019110168820582',
    //   path: 'pages/confirm/confirm',
    //   extraData:{
    //     "alipay_store_id":"2019110600077000000084416752"
    //   },
    //   success: (res) => {
    //     console.log(JSON.stringify(res))
    //   },
    //   fail: (res) => {
    //     console.log(JSON.stringify(res))
    //   }
    // });
    // return
    wx.reLaunch({
      url: '/pages/confirm/confirm'
    })
    // app.backMayi()
  },
  attention() {
    const scene_id = app.globalData.station.myjy_source
    spreadModel.getLink(scene_id).then(res => {
      console.log(res)
    })
  },
  showTime() {
    let downTime = 0
    timerCountDown = setInterval(() => {
      downTime += 6
      const countDownTime = format.watch(downTime)
      this.setData({
        countDownTime: countDownTime
      })
    }, 60);
    timerDate = setInterval(() => {
      const time = format.date("yyyy年MM月dd日 hh:mm:ss", new Date())
      this.setData({
        time: time
      })
    }, 1000);

  },
  onHide() {
    // 页面隐藏
  },
  onUnload() {
    // 页面被关闭
    this.clearTimer()
  },
  clearTimer(){
    clearTimeout(timerCountDown)
    clearTimeout(timerDate)
  }
});